package com.jxd.config;


import org.apache.hadoop.hbase.client.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Configuration
public class HbaseConfig {
    @Value("${hbase.bwhead.tablename}")
    private String bwHeadTableName;
    @Value("${hbase.bwcontent.tablename}")
    private String bwContentTableName;
    @Value("${hbase.zookeeper.property.clientPort}")
    private  String clientPort;
    @Value("${hbase.zookeeper.quorum}")
    private  String clientQuorum;
    private  org.apache.hadoop.conf.Configuration configuration;
    private  Connection hbaseConnection = null;
    @Bean
 public  HTable getHtableByMesHead(){
        HTable hTable = null;
        org.apache.hadoop.conf.Configuration  conf = HBaseConfiguration.create();
        try {
            hTable = new HTable(conf,bwHeadTableName);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println("打开表失败，异常信息为"+e);
        }
        return hTable;
    }
@Bean
public  HTable getHtableByMesContent(){
    HTable hTable = null;
    org.apache.hadoop.conf.Configuration  conf = HBaseConfiguration.create();
    try {
        hTable = new HTable(conf,bwContentTableName);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        System.out.println("打开表失败，异常信息为"+e);
    }
    return hTable;
}
@Bean
    public Connection HbaseConnection(){

    configuration= HBaseConfiguration.create();
    System.out.println(clientPort);
    System.out.println(clientQuorum);
    configuration.set("hbase.zookeeper.property.clientPort",clientPort);
    //引用外部配置问件 现在先行调试 zookeeper 服务器地址
    configuration.set("hbase.zookeeper.quorum",clientQuorum);
    ExecutorService threads = Executors.newFixedThreadPool(20);//手动？
    try {
        hbaseConnection = ConnectionFactory.createConnection(configuration, threads);
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("链接创建失败，异常信息为"+e);
    }
        return  hbaseConnection;
}
}
